// -*- C++ -*-
/*!
 * @file  TimerTest_send.cpp
 * @brief 
 *
 */
#include <string.h>
#include <iostream>
#include <boost/bind.hpp>
#include "TimerTest_send.h"

// Module specification
// <rtc-template block="module_spec">
static const char* timertest_spec[] =
{
    "implementation_id", "TimerTest_send",
    "type_name",         "TimerTest_send",
    "description",       "TimerTest_send component",
    "version",           "1.0",
    "vendor",            "leus, JSK",
    "category",          "vb_utility",
    "activity_type",     "TimerTest_sendComponent",
    "max_instance",      "10",
    "language",          "C++",
    "lang_type",         "compile",
    ""
};
// </rtc-template>
TimerTest_send::TimerTest_send(RTC::Manager* manager)
    : RTC::DataFlowComponentBase(manager),
      m_CommandServicePort("CommandService")
      // <rtc-template block="initializer">
      // </rtc-template>
{
}

TimerTest_send::~TimerTest_send()
{
}

RTC::ReturnCode_t TimerTest_send::onInitialize()
{
    // Registration: InPort/OutPort/Service
    // <rtc-template block="registration">
    // Set InPort buffers
    
    // Set OutPort buffer
  
    // Set service provider to Ports
        
    // Set service consumers to Ports
    m_CommandServicePort.registerConsumer("commandservice0", "CommandService", m_commandservice);  
    // Set CORBA Service Ports
    addPort(m_CommandServicePort);
        
    // </rtc-template>    
    return RTC::RTC_OK;
}


/*
  RTC::ReturnCode_t TimerTest_send::onFinalize()
  {
  return RTC::RTC_OK;
  }
*/

/*
  RTC::ReturnCode_t TimerTest_send::onStartup(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/

/*
  RTC::ReturnCode_t TimerTest_send::onShutdown(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/


RTC::ReturnCode_t TimerTest_send::onActivated(RTC::UniqueId ec_id)
{
    m_timer.start();
    return RTC::RTC_OK;
}


RTC::ReturnCode_t TimerTest_send::onDeactivated(RTC::UniqueId ec_id)
{
    return RTC::RTC_OK;
}


RTC::ReturnCode_t TimerTest_send::onExecute(RTC::UniqueId ec_id)
{
    std::string ret;

    ret=m_commandservice->command("servicetest", "hoge");
    //ret=command_via_serviceport(std::string("servicetest"), std::string("hoge"));
    std::cerr << "Result is: " << ret << std::endl;
    
    return RTC::RTC_OK;
}

std::string TimerTest_send::servicetest(const std::string &argv)
{
    std::cerr << "Input from serviceport is " << argv << std::endl;
    return ":serviceinput ok";
}

/*
  RTC::ReturnCode_t TimerTest_send::onAborting(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/

/*
  RTC::ReturnCode_t TimerTest_send::onError(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/

/*
  RTC::ReturnCode_t TimerTest_send::onReset(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/

/*
  RTC::ReturnCode_t TimerTest_send::onStateUpdate(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/

/*
  RTC::ReturnCode_t TimerTest_send::onRateChanged(RTC::UniqueId ec_id)
  {
  return RTC::RTC_OK;
  }
*/



extern "C"
{
 
    void TimerTest_sendInit(RTC::Manager* manager)
    {
        coil::Properties profile(timertest_spec);
        manager->registerFactory(profile,
                                 RTC::Create<TimerTest_send>,
                                 RTC::Delete<TimerTest_send>);
    }
  
};
